package com.ebt.m.proposal_v2.widget.dialog;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.proposal_v2.adapter.EBTListDialogAdapter;
import com.ebt.m.proposal_v2.base.CompatDialog;
import com.ebt.m.proposal_v2.widget.callback.OnRecyclerItemClickListener;
import com.ebt.m.view.RecyclerViewItemDivider;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author archer.qi
 *         Created on 2017/5/10.
 */
public class EBTListDialog extends CompatDialog {

    @BindView(R.id.EBTListDialog_header)
    TextView dialogHeader;
    @BindView(R.id.EBTListDialog_list)
    RecyclerView dialogList;

    private String mTitleText;
    private EBTListDialogAdapter mAdapter;
    private OnRecyclerItemClickListener mListener;

    public EBTListDialog(Context context) {
        super(context);
    }

    @Override
    protected int contentViewResource() {
        return R.layout.dialog_ebt_list;
    }

    @Override
    protected void onCreateView() {
        initRecyclerView();
    }

    private void initRecyclerView() {
        dialogList.setLayoutManager(new LinearLayoutManager(mContext));
        dialogList.addItemDecoration(new RecyclerViewItemDivider(mContext, LinearLayoutManager.VERTICAL)
                        .setAppearance(1, "#ffdddddd"));
    }

    public EBTListDialog setTitle(String title) {
        mTitleText = title;
        return this;
    }

    /*public EBTListDialog setData(ArrayList<String> data) {
        mAdapter = new EBTListDialogAdapter(mContext, data);
        return this;
    }

    public EBTListDialog setData(String[] data) {
        mAdapter = new EBTListDialogAdapter(mContext, data);
        return this;
    }*/

    public EBTListDialog setOnItemClickListener(OnRecyclerItemClickListener listener) {
        mListener = listener;
        return this;
    }

    @Override
    public void show() {
        super.show();
        if (mTitleText != null && mTitleText.length() > 0) {
            dialogHeader.setText(mTitleText);
        }
        if (mAdapter != null) {
            dialogList.setAdapter(mAdapter);
        }
        if (mAdapter != null && mListener != null) {
            mAdapter.setOnItemClickListener(mListener);
        }
    }
}
